#include <stdio.h>
#include <unistd.h>
#include <dlfcn.h>
#include <string.h>
#include <sys/types.h>
#include <stdarg.h>

typedef int request_t;

int open(const char *pathname, int flags, mode_t mode) {
printf("\e[32;1m[Hook]\e[0m %s\n", pathname);

int (*new_open)(const char *pathname, int flags, mode_t mode);
int result;
new_open = dlsym(RTLD_NEXT, "open");
int retval;
retval = new_open(pathname, flags, mode);
if(retval < 0)
return 9999999;
return retval;
}

int ioctl (int fd, request_t request, ...){
static int (*func_ioctl) (int, request_t, void *) = NULL;
va_list args;
void *argp;
if (! func_ioctl)
func_ioctl = (int (*) (int, request_t, void *)) dlsym (RTLD_NEXT, "ioctl");
va_start (args, request);
argp = va_arg (args, void*);
va_end (args);

if (fd == 9999999)
return 0;
return func_ioctl (fd, request, argp);
}

